import { FieldType } from "../celltypes";
import CellType from "../celltypes";

export default {
    canUndo: true,
    execute: (context, options, isUndo) => {
        const { sheet, value, row, col } = options;
        const ReportFieldCellType = CellType('ReportFieldCellType');
        sheet.suspendPaint();
        const cellRange = sheet.getRange(row, col);
        if (isUndo) {
            cellRange.cellType(options._oldCellType);
        } else {
            options._oldCellType = cellRange.cellType();
            const cellType = new ReportFieldCellType();
            cellType.label = value;
            cellType.fieldType = FieldType.ConstText;
            cellRange.cellType(cellType);
        }
        sheet.resumePaint();
    }
};